package com.shop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shop.entity.PmsBrand;
import com.shop.service.PmsBrandService;
import com.shop.vo.ResultJson;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author lpx610
 * @since 2023-11-02
 */
@RestController
@RequestMapping("/pmsBrand")
public class PmsBrandController {

    @Resource
    private PmsBrandService pmsBrandService;

    @GetMapping("/list")
    public ResultJson<IPage<PmsBrand>> list (Integer pageNo, Integer pageSize, String name, Integer order) {
        return ResultJson.success(pmsBrandService.list(pageNo, pageSize, name, order));
    }

    @GetMapping("/getById")
    public ResultJson<PmsBrand> getById(String id) {
        return ResultJson.success(pmsBrandService.getById(id));
    }

    @PostMapping("/add")
    public ResultJson<Boolean> add(String name, String description, MultipartFile file) {
        return ResultJson.success(pmsBrandService.add(name, description, file), "品牌新增成功");
    }

    @PostMapping("/update")
    public ResultJson<Boolean> update(String id, String name, String description, MultipartFile file) {
        return ResultJson.success(pmsBrandService.update(id, name, description, file), "品牌更新成功");
    }

    @GetMapping("/delete")
    public ResultJson<Boolean> delete(String id, Boolean active) {
        return ResultJson.success(pmsBrandService.delete(id, active), active ? "品牌启用成功" : "品牌禁用成功");
    }

}
